package com.xiaoshuidi.cloud.module.rooms.mq.producer;

import com.xiaoshuidi.cloud.framework.systemevent.core.LeaseSystemEventProducer;
import com.xiaoshuidi.cloud.framework.systemevent.core.data.LeaseSystemEventBooking;
import com.xiaoshuidi.cloud.framework.systemevent.core.data.LeaseSystemEventBookingCancel;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;

/**
 * @Author Feng
 * @date 2023/7/7
 */
@Component
public class ReserveProducer {

    @Resource
    private LeaseSystemEventProducer producer;

    /**
     * 预定成功发送消息
     *
     * @param id
     * @param tenantId
     * @param bookingDate
     * @param memberId
     * @param apartmentId
     * @param deposit
     */
    public void paymentSuccess(Long id, Long tenantId, LocalDateTime bookingDate, Long memberId, Long apartmentId, BigDecimal deposit) {
        LeaseSystemEventBooking booking = new LeaseSystemEventBooking();
        booking.setApartmentId(apartmentId);
        booking.setBookingDate(Date.from(bookingDate.toInstant(ZoneOffset.ofTotalSeconds(8))));
        booking.setBookingId(id);
        booking.setDeposit(deposit);
        booking.setTenantId(tenantId);
        booking.setUserId(memberId);
        producer.send(booking);
    }

    /**
     * 预定取消发送消息
     *
     * @param id
     * @param tenantId
     * @param memberId
     * @param apartmentId
     */
    public void paymentCancel(Long id, Long tenantId, Long memberId, Long apartmentId) {
        LeaseSystemEventBookingCancel booking = new LeaseSystemEventBookingCancel();
        booking.setTenantId(tenantId);
        booking.setUserId(memberId);
        booking.setBookingId(id.toString());
        booking.setApartmentId(apartmentId);
        producer.send(booking);
    }
}
